package com.windfone.common;
import java.util.Properties;

import javax.mail.Session;
import javax.mail.internet.MimeMessage;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
 
public class HTMLMail { 
	private static JavaMailSenderImpl senderImpl;
	private String toAddress;
	private String content;
	private String title;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getToAddress() {
		return toAddress;
	}
	public void setToAddress(String toAddress) {
		this.toAddress = toAddress;
	}
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}


 
public  void send() throws Exception{
	if ( senderImpl == null ){
		senderImpl = new JavaMailSenderImpl(); 
    	senderImpl.setHost("mail.windfone.com"); 
        senderImpl.setUsername("postmaster") ;  
        senderImpl.setPassword("szyxdtel1688") ;  
        Properties prop = new Properties() ;
        prop.put("mail.smtp.auth", "true") ;  
        prop.put("mail.smtp.timeout", "25000") ;
        prop.put( "mail.smtp.auth" ,  "true" ) ;   
        prop.put( "mail.smtp.timeout " ,  "25000" );
        prop.put("mail.smtp.host", "mail.windfone.com");

        MyAuthenticator myauth = new MyAuthenticator("postmaster@windfone.com", "szyxdtel1688");
        Session session = Session.getDefaultInstance(prop, myauth);
        senderImpl.setSession(session);
	}
    MimeMessage mailMessage = senderImpl.createMimeMessage(); 
    MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage); 
    messageHelper.setTo( toAddress ); 
    messageHelper.setFrom("postmaster@windfone.com"); 
    messageHelper.setSubject(  title ); 
    messageHelper.setText( content,true); 
    senderImpl.send(mailMessage); 
} 
} 
